home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
magazine
/
c_news
/
16
/
sets
/
setsourc
/
sets.h
< prev
next >
Wrap
Text File
|
1989-02-26
|
5KB
|
119 lines
/* sets.h -- Header file for implementation of data type, set, in C
by Arnold S. Cherdak, February 26, 1989.
First implementation for Turbo-C, Version 2.0
DISCLAIMER - DISCLAIMER - DISCLAIMER - DISCLAIMER - DISCLAIMER
Use at your own risk, The author is NOT responsible for ANY
damages resulting from the use, proper or improper, of this
software.
References for this implementation were:
Cooper, Doug, STANDARD PASCAL, USER REFERENCE MANUAL,
1983, W.W. Norton & Co., New York.
Koffman, E. B., PROBLEM SOLVING AND STRUCTURED PROGRAMMING
IN PASCAL, Second Ed., 1985, Addison-Wesley, Reading, Mass.
The Institute of Electrical and Electronics Engineers, Inc.,
AN AMERICAN NATIONAL STANDARD, IEEE STANDARD PASCAL COMPUTER
PROGRAMMING LANGUAGE (ANSI/IEEE 770X3.97-1983), 1983, Wiley.
Kernighan, Brian W., and Ritchie, Dennis M., THE C PROGRAMMING
LANGUAGE, 1978, Prentice-Hall, Englewood Cliffs, NJ.
Schwaderer, W. David, C WIZARD'S PROGRAMMING REFERENCE, 1985,
Wiley.
*/
#define BITS_PER_INTEGER 16 /* for MS-DOS systems on 8/16-bit machines */
/* Use function wordlength() to find out. */
#define MEMBERS_PER_WORD BITS_PER_INTEGER
#define MAX_MEMBERS 256 /* This parameter is an upper limit that can */
/* be changed as desired. It's a compromise */
/* to save space. Can be up to 32K for a */
/* 16-bit integer size. */
#define NOCHANGE (2)
#define SUCCESS (1)
#define FAILURE (0)
#define _E -2 /* END_OF_LIST; used to terminate input list */
/* of set members */
#define __ ,-1, /* 'thru, __ ' used to denote contiguous */
/* set members as in 'A'__'B'. i.e. double */
/* underscore rather than two dots, ".." */
typedef enum {FALSE=0, TRUE=1} boolean; /* needed for return values */
/* These are all the ordinal types permitted to be set base types. All
these are predefined in Pascal. The subrange type is as defined in Pascal
and consists of a contiguous range of integer values. Character and
Boolean are predefined types having 256 and 2 members, respectively, in
MS-DOS implementations. Enum and Subrange are type classes that can have
numerous types. However, ANSI C doesn't do type checking of ENUM types.
These were left to the user to be careful about how they are used.
Note that type UNIVERSAL is not intended for the user but, rather, for
internal use as may be seen in the functions for intersection, difference,
etc. It might be useful, however, in debugging since type checking of
base_type, UNIVERSAL, sets is suspended.
Note also that base_type, SUBRANGE, stands in for integer and enumerated
types. Enumerated type set applications are straightforward and need
little, if any, explanation, especially to Pascal programmers. The
application to integer subranges, though, deserves a word. All set
members are numbered from 0..nmembers. As a result, an integer subrange
that lies fully or partially outside this range may result in an error
message or, worse, improper operation. It would be a good thing to keep
integer subranges within the nmember limit or convert them to an enumerated
type by placing a letter before the number. i.e., X300..X310. Another
option would be to expand MAX_MEMBERS to include the subrange.
*/
typedef enum {UNIVERSAL, BOOLEAN, CHARACTER, ENUMERATED, SUBRANGE} base;
/* The following structure IS a set */
typedef struct SET {
base base_type;
int set_size;
int nmembers;
int member_recs;
int set_tag;
unsigned word[MAX_MEMBERS / MEMBERS_PER_WORD];
} set;
/* This macro provides a set declaration and should be used whenever a
set object must be declared.
*/
#define defset(set_name,bastyp,size,tag) struct SET set_name\
= {bastyp,size,0,((size/MEMBERS_PER_WORD)+(size%MEMBERS_PER_WORD?1:0)),tag}
/* FUNCTION PROTOTYPES FOR SET FUNCTIONS */
void dump_set(set *aset);
void set_print(set *aset);
unsigned wordlength(void);
int add_member(set *aset, int member);
int del_member(set *aset, int member);
boolean in_set(set *aset, int entity);
int set_assign(set *destination, set *source);
void set_clear(set *aset);
int check_set_types(set *set1, set *set2);
int set_intersect(set *intersect, set *set1, set *set2);
int set_union(set *xunion, set *set1, set *set2);
int set_difference(set *difference, set *minuend, set *subtrahend);
int set_member_count(set *aset);
boolean set_equality(set *left, set *right);
boolean set_inequality(set *left, set *right);
boolean set_included_in(set *left, set *right);
boolean set_includes(set *left, set *right);
boolean cmp_base_types(set *seta,set *setb);
boolean cmp_set_tags(set *seta,set *setb);
int set_of(set *aset,...);
int set_args(set *aset, va_list ap);
/* END set.h */